﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LongQuanWeb.App_Code;

namespace LongQuanWeb.Admin
{
    public partial class MemberList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((this.Session["username"] == null) || (this.Session["username"].ToString() == string.Empty))
            {
                base.Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                base.Response.Write("<a href='Login.aspx' target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                base.Response.End();
            }
            if (!IsPostBack)
            {
                base.Response.Write("<script>parent.window.document.getElementById( 'lbl_title').innerHTML='会员信息'; </script>");
                BindRpt();
            }
        }

        protected void gv_new_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "show")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                Response.Redirect("MemberShow.aspx?id=" + id + "");
            }
            else if (e.CommandName == "audit")//审核
            {
                if (e.CommandArgument.ToString().Trim().Split('|')[1].ToString().Trim() == "1")//审核
                {
                    string strSql = "Update [User] Set Status='0' where UserCode=" + int.Parse(e.CommandArgument.ToString().Trim().Split('|')[0]) + "";
                    if (DbHelperSQL.ExecuteSql(strSql) > 0)
                    {
                        BindRpt();
                        base.Response.Write("<script>alert('取消审核成功！');window.location='MemberList.aspx'</script>");
                    }
                    else
                        base.Response.Write("<script>alert('取消审核失败！');</script>");
                }
                else//未审核
                {
                    string strSql = "Update [User] Set Status='1' where UserCode=" + int.Parse(e.CommandArgument.ToString().Trim().Split('|')[0]) + "";
                    if (DbHelperSQL.ExecuteSql(strSql) > 0)
                    {
                        BindRpt();
                        base.Response.Write("<script>alert('审核成功！');window.location='MemberList.aspx'</script>");
                    }
                    else
                        base.Response.Write("<script>alert('审核失败！');</script>");
                }
                
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindRpt();
        }

        private void BindRpt()
        {
            string strWhere = "";
            if (rbn_all.Checked)
            {
                strWhere = " 1=1";
            }
            else if (rbn_yes.Checked)
            {
                strWhere = " Status='1'";
            }
            else if (rbn_no.Checked)
            {
                strWhere = " Status<>'1'";
            }
            string strSql = "select count(*) from [User] Where " + strWhere + "";
            AspNetPager1.RecordCount = int.Parse(DbHelperSQL.Query(strSql).Tables[0].Rows[0][0].ToString());
            strSql = "select * from [User] Where " + strWhere + " Order By UserCode desc";
            DataTable dt = DbHelperSQL.GetListDataSet(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, strSql);
            this.gv_active.DataSource = dt;
            this.gv_active.DataBind();
        }

        protected void rbn_all_CheckedChanged(object sender, EventArgs e)
        {
            BindRpt();
        } 
    }
}
